#pragma once
#include <deque>
#include "RWCriticalSection.h"

class IScreenShotReceiver
{
public:
	virtual void ReceiveCaption(TCHAR *iCaption) = 0;
	virtual void ReceiveScreenShot(HBITMAP iBitmapId) = 0;
};


class WindowDataGrabber
{
	typedef std::pair<HWND, IScreenShotReceiver*> HwndReceiver;
	std::deque<HwndReceiver>Receivers;

	bool				UsePw;	
	UINT				Interval;
	HANDLE				Thread;
	HANDLE				StartEvent;
	CRWCriticalSection	SyncObject;
	
protected:
	static unsigned int __stdcall WatcherFunction(void *iParams);
	static void CALLBACK TerminateProc(ULONG_PTR dwParam);


public:
	WindowDataGrabber();
	
	bool Start(UINT iInterval, bool iUsePrintWindow=true);
	void AddReceiver(HWND iHwnd, IScreenShotReceiver *iReceiver);
	void RemoveReceiver(HWND iHwnd);
	void RemoveReceiver(IScreenShotReceiver *iReceiver);
	void Stop();

	~WindowDataGrabber();
};
